<template>
  <div>
    <el-select v-model="selectValue" filterable size="small" class="selectEnterprise" @change="getSelectValue">
      <el-option
        v-for="item in enterpriseList"
        :key="item.company_id"
        :label="item.company_name"
        :value="item.company_id">
      </el-option>
    </el-select>
  </div>
</template>
<script>
import {reqListCorps} from '@/api/enterprise/index'
import {mapGetters} from "vuex";
export default {
  name: "changeEnterprise",
  props: ['value'],
  data() {
    return {
      selectValue: null,
      enterpriseList:[],
    }
  },
  watch: {
    value(val) {
      this.selectValue = val;
      this.$store.commit('SET_ENTERPRPRISEID', val)
    }
  },
  computed: {
    // 使用对象展开运算符将此getter映射到局部计算属性
    ...mapGetters([
      'enterpriseId' // 假设这是你想要监听的getter的名字
    ]),
  },
  created() {

    this.getListCorps();

  },
  methods: {
    getListCorps(){
      reqListCorps().then((res)=>{
        console.log('获取的企业',res);
        this.enterpriseList=res.data;

        this.selectValue=this.enterpriseId?this.enterpriseId: this.enterpriseList[0].company_id;
        this.$store.commit('SET_ENTERPRPRISEID', this.selectValue);
      })
    },
    getDelById(id){
      this.$msgBox.showMsgBox({
        title: "你确定删除该企业？",
        content: "删除企业需先删除该企业所属的所有企微号可在管理企微号页面删除企微号",
      })
        .then(async (val) => {
          //调用接口
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    getSelectValue(val) {
      this.$emit('input',val);
    }
  },
}
</script>

<style scoped lang="scss">
.selectEnterprise {
  ::v-deep .el-input__inner {
    background-color: #eff3ff !important;
    border-color: #eff3ff;
  }
}

.other-option {
  padding: 0 8px;
  color: #2f54eb;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid #e9e9e9;
}

.select-option-item {
  display: flex;
  justify-content: space-between;
  align-items: center;

  i {
    display: none;
  }

  &:hover i {
    display: inline-block;
  }
}
</style>
